<?php

    class ContactUtil{
        public static function getContactModelList($custno,$locno){
            $contacts   = Locationcontacts::model()->findAll("locno='$locno' and custno='$custno'");
            $globalContacts = Locationcontacts::model()->findAll("locno='00000' and custno='$custno'");
            return array_merge($contacts,$globalContacts);
        }

        public static function getContactData($custno,$locno,$salesPersonNumber = null){
            $contacts   = Locationcontacts::model()->findAll("locno='$locno' and custno='$custno'");
            $data       = array();
            
            foreach ($contacts as $contact)
            {
                $data[$contact->email] = $contact->contact . ' - ' . $contact->email . ' - ' . $contact->jobtitle;
            }
            
            $globalContacts = Locationcontacts::model()->findAll("locno='00000' and custno='$custno'");
            foreach ($globalContacts as $contact)
            {
                $data[$contact->email] = 'G: '.$contact->contact . ' - ' . $contact->email . ' - ' . $contact->jobtitle;
            }
            
            if($salesPersonNumber!=null){
                $salesPerson = Employees::model()->findByPk($salesPersonNumber);
                if ($salesPerson != null)
                {
                    $data[$salesPerson->workemail] = 'Sales Person' . ' - ' . $salesPerson->workemail;
                }
            }
            
            $presidentContract = Employees::model()->findByPk('1109');
            if ($presidentContract != null)
            {
                $data[$presidentContract->workemail] = 'Greg Cahoe' . ' - ' . $presidentContract->workemail;
            }

            if (empty($data))
                $data = array('N/A', 'N/A');
            
            return $data;
        }
    }
?>
